<template>
    <div class="nav">
        <el-card class="box-card">
  <div slot="header" class="clearfix">
    <span>登陆</span>
    <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
  </div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="账号" prop="username">
    <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="pass">
    <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
</el-card>
    </div>
</template>

<script>
import http from 'axios'
export default {
    data() {
     
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        }
          callback();
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        }
          callback();
      };
      return {
        ruleForm: {
          username: '',
          pass: '',
       
        },
        rules: {
          username: [
            { validator: validatePass, trigger: 'blur' }
          ],
          pass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
        
        }
      };
    },
    methods: {
      submitForm(formName) {
          console.log(111)
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // alert('submit!');
            // console.log(33)
            const parnms = {
                username:this.ruleForm.username,
                pass:this.ruleForm.pass
            }
            console.log(parnms);
            http.post('http://estate.eshareedu.cn/estate/api/administrator/checklogin',parnms).then((res)=>{
                    const {errCode} = res.data
                    const {token}=res.data.data
                    if(errCode == '10000'){
                        // console.log(444)
                      
                        this.$router.push('/shop'),
                        this.$message.success('登陆成功'),
                        sessionStorage.setItem('token',token)
                        console.log(res);
                    }else{
                        console.log(222)
                        console.log(res);
                    }
            })
          } else {
            console.log(555);
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped>
.nav{
  margin-left: 34%;
    margin-top: 13%;
}
     .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
  }
</style>